package com.android.webttest.Config;

import android.content.Context;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;


import com.android.webttest.dao.GoodFavoriteDao;
import com.android.webttest.dao.GoodLikeDao;
import com.android.webttest.dao.GoodShareDao;
import com.android.webttest.model.tableModel.GoodFavorite;
import com.android.webttest.model.tableModel.GoodLike;
import com.android.webttest.model.tableModel.GoodShare;
import com.android.webttest.model.tableModel.SearchHistoryRecord;
import com.android.webttest.dao.SearchHistoryDao;
// 如果有其他实体类，也导入进来
// import com.android.webttest.model.User;
// import com.android.webttest.model.Product;

@Database(
        entities = {
                SearchHistoryRecord.class,
                GoodLike.class,
                GoodFavorite.class,
                GoodShare.class
        },
        version = 6,
        exportSchema = false // 关闭自动导出数据库结构文件
)
public abstract class AppDatabase extends RoomDatabase {

    private static AppDatabase instance;

    // 声明 DAO 方法
    public abstract SearchHistoryDao searchHistoryDao();

    public abstract GoodLikeDao goodLikeDao();

    public abstract GoodFavoriteDao goodFavoriteDao();

    public abstract GoodShareDao goodShareDao();
    // public abstract UserDao userDao();
    // public abstract ProductDao productDao();

    public static synchronized AppDatabase getInstance(Context context) {
        if (instance == null) {
            instance = Room.databaseBuilder(context.getApplicationContext(),
                            AppDatabase.class, "app_database") // 数据库名称
                    .fallbackToDestructiveMigration() // 升级失败时重建数据库
                    .build();
        }
        return instance;
    }
}
